package com.huopaolan.yohuoshop.Mvp.Presenter;

import com.huopaolan.lib_core.Mvp.Presenter.BasePresenter;
import com.huopaolan.yohuoshop.Bean.HomeMenuEntity;
import com.huopaolan.yohuoshop.Mvp.Contract.HomeContract;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class HomePresenter extends BasePresenter<HomeContract.IHomeView, HomeContract.IHomeModel> {
    @Inject
    public HomePresenter(HomeContract.IHomeView iHomeView, HomeContract.IHomeModel iHomeModel) {
        super(iHomeView, iHomeModel);
    }

    //发起获取菜单列表网络请求
    public void requestMenu() {
        m.homeMenu().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<HomeMenuEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        v.showDialog();
                    }

                    @Override
                    public void onNext(HomeMenuEntity homeMenuEntity) {
                        v.success(homeMenuEntity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        v.hideDialog();
                        v.showMessage("" + e);
                    }

                    @Override
                    public void onComplete() {
                        v.hideDialog();
                    }
                });
    }
}
